import request from '@/utils/httpRequest'
import { AxiosPromise } from 'axios'
// import { UserForm, UserInfo, UserPageVO, UserQuery } from './user_types'
import { TypeUserFormI, TypeUserInfoI, TypeUserPageVoI, TypeUserQueryI ,TypePasswordChangeFormI} from './user_types'

//done
//很多虽然有前端pai,但是无mock对应的模拟

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 * @returns response
 */
export function getUserInfoApi(): AxiosPromise<TypeUserInfoI> {
    return request({
        url: '/api/v1/users/me',
        method: 'get',
    })
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(queryParams: TypeUserQueryI): AxiosPromise<TypeUserPageVoI> {
    return request({
        url: '/api/v1/users/page',
        method: 'get',
        params: queryParams,
    })
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getUserForm(userId: string): AxiosPromise<TypeUserFormI> {
    return request({
        url: '/api/v1/users/' + userId + '/form',
        method: 'get',
    })
}

/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
    return request({
        url: '/api/v1/users',
        method: 'post',
        data: data,
    })
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(id: number, data: TypeUserFormI) {
    return request({
        url: '/api/v1/users/' + id,
        method: 'put',
        data: data,
    })
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: number, password: string) {
    return request({
        url: '/api/v1/users/' + id + '/password',
        method: 'patch',
        params: { password: password },
    })
}

/**
 * 删除用户
 *
 * @param ids
 */
export function deleteUsers(ids: string) {
    return request({
        url: '/api/v1/users/' + ids,
        method: 'delete',
    })
}

/**
 * 下载用户导入模板
 *
 * @returns
 */
export function downloadTemplateApi() {
    return request({
        url: '/api/v1/users/template',
        method: 'get',
        responseType: 'arraybuffer',
    })
}

/**
 * 导出筛选用户
 *
 * @param queryParams
 * @returns
 */
export function exportQueryUser(queryParams: TypeUserQueryI) {
    return request({
        url: '/api/v1/users/exportQueryUser',
        method: 'get',
        params: queryParams,
        responseType: 'arraybuffer',
    })
}

/**
 * 导出全部用户
 *
 * @param queryParams
 * @returns
 */
export function exportAllUser() {
    return request({
        url: '/api/v1/users/exportAllUser',
        method: 'get',
        responseType: 'arraybuffer',
    })
}

/**
 * 导入用户
 *
 * @param file
 */
export function importUser(deptId: number, file: File) {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/api/v1/users/_import',
        method: 'post',
        params: { deptId: deptId },
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data',
        },
    })
}

  /** 修改个人中心用户密码 */
  export function changePassword(data: TypePasswordChangeFormI) {
    return request({
      url: `/api/v1/users/password`,
      method: "put",
      data: data,
    });
  }